import { UserProfilesAPI } from "@/request/Api"

export default {
    namespaced: true,
    state: {
        // 用户信息
        userInfo: {
            nickName: "--",
            coin: 0 ,
            headImg: require("../../assets/img/userImg.f8bbec5e.png")
        },
        // 购物车数量
        cartTotal: 66
    },
    mutations: {
        // 修改登录状态
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        // 初始化仓库属性
        initUserInfo(state){
            state.userInfo = {
                nickName: "--",
                coin: 0 ,
                headImg: require("../../assets/img/userImg.f8bbec5e.png")
            }
            state.cartTotal = 66;
        }
    },
    actions: {
        // 请求用户信息
        async asyncchangeUserInfo({ commit }) {
            // 1.请求用户信息
            let user = await UserProfilesAPI();
            // console.log("获取用户信息", user);
            // 更新vuex中用户信息  调用mutations
            commit("changeUserInfo", user.data)
        }
    }
}